package learning.utils;

import java.io.IOException;
import java.time.Duration;

// 使用示例
public class ExampleUsage {

    public static void main(String[] args) throws Exception {
        RetryExecutor retryExecutor = new RetryExecutor(3, Duration.ofSeconds(1), throwable -> throwable instanceof IOException
        );

        String result = retryExecutor.execute(() -> {
            // 假设这是需要重试的网络调用
            return makeNetworkCall();
        });

        System.out.println("成功获取数据：" + result);
    }

    private static String makeNetworkCall() throws IOException {
        // 实现网络调用逻辑，此处仅模拟抛出异常
        throw new IOException("模拟网络连接异常");
    }
}
